package cn.egame.extraction.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import cn.egame.common.exception.ExceptionCommonBase;
import cn.egame.extraction.dao.ParameterAppServiceDao;
import cn.egame.extraction.util.ConsVar;
import cn.egame.extraction.util.DateType.TimeType;
import cn.egame.interfaces.EnumType.AppParameterParamType;
import cn.egame.interfaces.pu.AppParameter;

public class ParameterAppService {
	private static ParameterAppService instance = null;
	private static byte[] lock = new byte[0];
	private Logger log = Logger.getLogger(ParameterAppService.class);
	List<Integer> ids = new ArrayList<Integer>();
	List<AppParameter> lists = new ArrayList<AppParameter>();
	Map<String, Integer> map = new HashMap<String, Integer>();
	public static ParameterAppService getInstance() throws ExceptionCommonBase {
		if (instance == null) {
			synchronized (lock) {
				if (instance == null) {
					instance = new ParameterAppService();

				}
			}
		}
		return instance;
	}

	private static ParameterAppServiceDao dao = null;

	public ParameterAppService() throws ExceptionCommonBase {
		dao = new ParameterAppServiceDao();
		ids = dao.listAppParameterIdsByParentId(ConsVar.RANK,ConsVar.APPID);
		lists = dao.listAppParameterByIds(ids);
		init();
	}

	public void getParamterAppIdByTimeType(TimeType type)
			throws ExceptionCommonBase {

		if (ids != null && ids.size() > 0) {
			if (lists != null && lists.size() > 0) {
				for (AppParameter app : lists) {
					if (app.getValueBoolean(type.getRankType().getValue())) {
						map.put(type.getValue()+"", GameTagService
								.getInstance().getGameTagId(app.getId() + ""));
					}
				}
			}
		}
	}

	public void init() throws ExceptionCommonBase {
		for (TimeType type : TimeType.values()) {
			getParamterAppIdByTimeType(type);
		}
	}
	
	 public List<Integer> listAppParameterIdsByParam(AppParameterParamType param) throws ExceptionCommonBase {
		return dao.listAppParameterIdsByParam(param);
	}

}
